package kz.kstu.scantest.business.util;

import java.io.*;

/**
 * @author Filipp_Stankevich
 *         created 02.09.12 9:45
 */
public class FileUtil {

    public static void writeToFile(String fileName, String text) throws IOException {
        FileOutputStream outputStream = new FileOutputStream(fileName);
        OutputStreamWriter streamWriter = new OutputStreamWriter(outputStream);
        BufferedWriter writer = new BufferedWriter(streamWriter);
        writer.write(text);
        writer.close();
    }

    public static String readFromFile(String fileName) throws IOException {
        FileInputStream inputStream = new FileInputStream(fileName);
        InputStreamReader streamReader = new InputStreamReader(inputStream);
        BufferedReader reader = new BufferedReader(streamReader);
        StringBuilder builder = new StringBuilder();
        String line = reader.readLine();
        while (line != null) {
            builder.append(line);
            line = reader.readLine();
        }
        return builder.toString();
    }
}
